﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using ECCSystem.EntityClass;
using ECCSystem.BizRule;

namespace ECCSystem.DataAccess
{
	class ClsWorkTime : DBObject
	{

		public int GetList(DateTime objDateTime)
		{
			int intCount = 0;

			SqlParameter[] parameters = new SqlParameter[] { 
													new SqlParameter("@WorkTime_Date", SqlDbType.DateTime)
													};
			parameters[0].Value = objDateTime;
			return this.RunProcedure("sp_WorkTime_GetList", parameters, ref intCount);
		}

		public int DelWorkTime(DateTime objDateTime)
		{
			int intCount = 0;

			SqlParameter[] parameters = new SqlParameter[] { 
													new SqlParameter("@WorkTime_Date", SqlDbType.DateTime)
													};
			parameters[0].Value = objDateTime;
			this.RunProcedure("sp_WorkTime_Delete", parameters, ref intCount);
			return intCount;
		}

		public string AddWorkTime(ArrayList objArr, SqlTransaction objTran)
		{
			try
			{

				SqlCommand objCmd = new SqlCommand("sp_WorkTime_Add", BizRule.ClsCommon.gObjConn);
				int rowsAffected = 0;
				if (objArr == null)
				{
					return "";
				}
				for (int k = 0; k < objArr.Count; k++)
				{
					ArrayList arr = new ArrayList();
					arr = (ArrayList)objArr[k];
					for (int i = 0; i < arr.Count; i++)
					{
						WorkTimeEntity objEntity = new WorkTimeEntity();
						objEntity = (WorkTimeEntity)arr[i];
						//if (objEntity.WorkTime_Status == "")
						//{
						//    return "";
						//}
						SqlParameter[] parameters = new SqlParameter[] { 
																new SqlParameter("@WorkTime_Date", SqlDbType.DateTime),
																new SqlParameter("@Name", SqlDbType.NVarChar,100),
																new SqlParameter("@WorkTime_Status", SqlDbType.NVarChar,50)
																	};
						parameters[0].Value = objEntity.WorkTime_Date;
						parameters[1].Value = objEntity.Name;
						parameters[2].Value = objEntity.WorkTime_Status;

						this.RunProcedure("sp_WorkTime_Add", parameters, ref rowsAffected, objTran, objCmd);

						if (rowsAffected == 0)
						{
							objTran.Rollback();
							return "1";
						}
					}
				}
				objTran.Commit();
				return "";
			}
			catch (Exception ex)
			{
				objTran.Rollback();
				return ex.ToString();
			}


		}
	}
}
